package tjx.Action;

import com.opensymphony.xwork2.ActionContext;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;

import static com.opensymphony.xwork2.Action.ERROR;
import static com.opensymphony.xwork2.Action.SUCCESS;

public class LoginAction implements Action {
    private String username;
    private String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    public String execute()throws Exception
    {
        ActionContext actionContext=ActionContext.getContext();
        Integer counter=(Integer)actionContext.getApplication().get("counter");
        if(counter==null)
        {
            counter=1;
        }
        else
        {
            counter=counter+1;
        }
        actionContext.getApplication().put("counter",counter);
        actionContext.getSession().put("user",getUsername());
        if (getUsername().equals("crazy.org")&&getPassword().equals("leegang"))
        {
            actionContext.put("tip","服务期提示：您已经成功登录");
            return SUCCESS;
        }
        actionContext.put("tip","服务期提示：登录失败");
        return ERROR;

    }
    public Object getValue(String key) {
        return null;
    }

    public void putValue(String key, Object value) {

    }

    public void setEnabled(boolean b) {

    }

    public boolean isEnabled() {
        return false;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {

    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {

    }

    public void actionPerformed(ActionEvent e) {

    }


}
